#ifndef _PANEL_H
#define _PANEL_H

#include "MyLinkedList.h"
#include "GraphicElement.h"



class Panel : public GraphicElement
{

private:

	MyLinkedList <GraphicElement> *nodes;

public:
	Panel(int x, int y, int width, int height): GraphicElement(x, y, width, height, NULL)
	{
		nodes = new MyLinkedList<GraphicElement>();
	}

	void addChild(GraphicElement *ge)
	{
		nodes->add(ge, true);
		ge->getDimensions()->x += dimensions->x;
		ge->getDimensions()->y += dimensions->y;
	}

	void Draw(HDC hdc)
	{

		// draw self
		if(redraw)
		{
			Graphics *g = Graphics::FromHDC(hdc);
			Pen			penBorder(PANEL_BORDER_COLOR);
			SolidBrush  brush(PANEL_BACKGROUND_COLOR);
			g->DrawRectangle(&penBorder, dimensions->x, dimensions->y, dimensions->width-1, dimensions->height-1);
			g->FillRectangle(&brush, dimensions->x+1, dimensions->y+1, dimensions->width-2, dimensions->height-2);
			delete g;
			redraw = false;
		}
	
		nodes->iteratorReset();
		GraphicElement *el = NULL;
		while((el = nodes->getNext()) != NULL)
		{
			el->Draw(hdc);
		}

	

	
	
	}

	void UpdateGraphics()
	{

		
		nodes->iteratorReset();
		GraphicElement *el = NULL;
		while((el = nodes->getNext()) != NULL)
		{
			el->UpdateGraphics();
		}
		redraw = true;
	}


	void MouseDown()
	{
		nodes->iteratorReset();
		GraphicElement *el = NULL;
		while((el = nodes->getNext()) != NULL)
		{
			el->MouseDown();
		}
	}

	void MouseUp()
	{
		nodes->iteratorReset();
		GraphicElement *el = NULL;
		while((el = nodes->getNext()) != NULL)
		{
			el->MouseUp();
		}
	}

	void Hover()
	{
		nodes->iteratorReset();
		GraphicElement *el = NULL;
		while((el = nodes->getNext()) != NULL)
		{
			el->Hover();
		}
	}

	~Panel() 
	{
		delete nodes;
	}

};


#endif